<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //  函数作业
        const arr = [
            { uname: '孙六', age: 39 },
            { uname: '刘七', age: 21 },
            { uname: '刘七', age: 1 },
            { uname: '张三', age: 59 },
            { uname: '李四', age: 29 },
            { uname: '王二', age: 19 },
        ]
        // 前提克隆一份数据
        const arr1 = JSON.parse(JSON.stringify(arr))
        // console.log(arr1);
        // 1，把age中个位数为9的替换成*  { uname: '孙六', age: 2* },
        arr1.forEach(item => {
            if (item.age % 10 === 9) {
                item.age = Math.floor(item.age / 10) + '*'
            }
        });
        // 2，把张三的这个对象干掉，添加个{uname:'老六',age: 12}
        arr1.forEach((item, index) => {
            if (item.uname === '张三') {
                arr1.splice(index, 1)
                arr1.push({ uname: '老六', age: 12 })
            }
        })
        // console.log(arr1);
        // 3, 根据年龄排序 过滤到小于18岁的
        const arr2 = arr.filter(item => {
            return item.age > 18
        })
        console.log(arr2);
    </script>
</body>

</html>